<?php

class Auth extends Controller {

	public function __construct()
	{
		parent::__construct();
	}

	public function index()	{
		$this->login();
	}

	public function login()	{
		$this->load->library('Form_validation');
    $this->form_validation->set_error_delimiters('', '');
		if ($this->prunuslib->is_logged_in()) {
			redirect('',location);
		} else {
			$val = $this->form_validation;
			
			// Set form validation rules
			$val->set_rules('txtUsername', lang('pr_Usuario'), 'trim|required|xss_clean');
			$val->set_rules('txtPassword', lang('pr_Contrasena'), 'trim|required|xss_clean');

			if ($val->run() AND $this->prunuslib->login($val->set_value('txtUsername'),$val->set_value('txtPassword')))	{
				redirect('', 'location');
			} else {
        $data['lastuser'] = get_cookie($this->config->item('PR_cookie_last_user'), TRUE);
        $data['logueado']=$this->prunuslib->is_logged_in();
        $data['error']=$this->prunuslib->resultado;
        $this->load->view('prunus/login',$data);
			}
		}  
	}
	public function logout() {
    $this->prunuslib->logout();
    redirect('',location);
  }
}

/* End of file auth.php */
/* Location: ./system/application/controllers/auth.php */